package com.ckerchina.admin.ckadmin.service.mgr;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import com.ckerchina.admin.ckadmin.dao.MgrUserDAO;
import com.ckerchina.admin.ckadmin.domain.mgr.MgrUser;

public class MgrUserDetailService implements UserDetailsService {

	@Autowired
	private MgrUserDAO mgrUserDAO;
 
	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		MgrUser mgrUser = mgrUserDAO.findByName(username);
		if (mgrUser == null) {
			throw new UsernameNotFoundException(username + " not found");
		}
		MgrUserDetail detail = new MgrUserDetail();
		detail.setUser(mgrUser);
		List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
		detail.setAuthorities(authorities);
		return detail;
	}   

}
